using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Utils.Extention;
using System.Linq;

namespace ChinaLeg.Web.WebAdmin.AdBar
{
    public partial class AdBarList : ChinaLeg.Web.Lib.PageBase
    {
        protected List<Model.Category> CateList;
        protected List<Model.AdPosition> AdList;

        protected void Page_Load(object sender, EventArgs e)
        {
            CateList = ChinaLeg.Cache.Category.Instance.GetList();
            AdList = ChinaLeg.BLL.AdPosition.Instance.GetList();
            if (!this.IsPostBack)
            {
                BindList();
            }
        }

        protected string GetCateName(int id)
        {
            var items = from p in CateList where p.Id == id select p;
            foreach (var item in items)
            {
                return item.CatName;
            }
            return "";

        }

        protected string GetAdPosiName(int id)
        {
            var items = from p in AdList where p.Id == id select p;
            foreach (var item in items)
            {
                return item.AdPostionName;
            }
            return "";
        }

        public void BindList()
        {
            string where = "";
            int recordCount;
            gvData.DataSource = ChinaLeg.BLL.AdBar.Instance.GetList(where, aspNetPager.PageSize, aspNetPager.CurrentPageIndex, out recordCount);
            gvData.DataBind();
            aspNetPager.RecordCount = recordCount;
        }
        protected void aspNetPager_PageChanged(object sender, EventArgs e)
        {
            BindList();
        }
        protected void gvData_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string cmd = e.CommandName.ToLower();
            int id = e.CommandArgument.ToInt32();
            switch (cmd)
            {
                case "del":
                    ChinaLeg.BLL.AdBar.Instance.Delete(id);
                    break;
                default:
                    break;
            }
            BindList();
        }

    }
}